// JavaScript Document

(function($) {


Drupal.behaviors.danFacebookBehavior = {
  attach: function (context, settings) {
	  $('div.fb-like-box').attr('data-width', window.screen.width+'px' );
  }
};
Drupal.behaviors.danColumnBehavior = {
  attach: function (context, settings) {
	 

$('#ul-place').masonry({
  itemSelector: 'li.item'
});


  }
};

Drupal.behaviors.danDestinationsBehavior = {
  attach: function (context, settings) {
    //code starts
	var w = window.screen.width;
	var li = document.querySelectorAll(".li-place");
	for (var i=0; i<li.length; i++) {

	}
	
	var pieces=document.querySelectorAll("#welcome-place"), t="", l="";
		for (var i=0; i<pieces.length; i++) {
			var width = $(pieces[i]).width();
			var	height = Math.round(0.9*width);
			//var bg = $(pieces[i]).css('background-image');
			pieces[i].style.height = height+'px';
			pieces[i].style.width = width+'px';
			pieces[i].style.overflow = 'hidden';
			pieces[i].style.backgroundRepeat ='no-repeat';
			pieces[i].style.backgroundPosition = 'center center';
			pieces[i].style.backgroundSize = 'auto '+pieces[i].style.height;
			$( pieces[i] ).mouseenter( 
									  function(){
					//$(this).css('background-image','none')
					$(this).css('opacity','0.6')
							  })
			.mouseleave(  function(){
					$(this).css('opacity','1')
					//$(this).css('background-image',bg)
										  } );
			
		}
 		
    //code ends
  }
};

Drupal.behaviors.danCoverBehavior = {
  attach: function (context, settings) {
    //code starts
	$(window).scroll(function(){
			var rate = 0.75*(window.screen.height/window.screen.width)
			var cover = document.getElementById("header-cover");
			var $cover = $('#header-cover');
			var w = window.screen.width;
			var h = Math.round($cover.width()*rate);
			
			var wh = $(window).height()
			var dh = $(document).height();
			var st = $(window).scrollTop();
			var sb = $(document).height() - $(window).height() - $(window).scrollTop();
			
//$('div.menubar').text('st-h => '+(st-h))
// when scrollTop;

if((st-h)<-150 ){
		
		$cover.height(h-st)
		$('div.brand-name').css('top', 0.4*(h-st)+'px')
		$cover.css('position', 'relative').css('z-index','0')
		cover.style.backgroundSize = w+'px auto'
		cover.style.backgroundPosition = 'center center';
		
		}else{
		$cover.height(100)
		.css('position', 'fixed')
		.css('z-index','999')
		.css('background-size',w+'px auto')
		$('div.brand-name').css('top', '5px')
		cover.style.backgroundSize = w+'px auto'
		}
	
	}) .scroll(); 
	//$( document ).height();
	var rate = 0.75*(window.screen.height/window.screen.width)
	var h = Math.round($('#header-cover').width()*rate);
	var cover = document.getElementById("header-cover");
	//alert(cover.style.backgroundImage);
	cover.style.width = '100%'
	cover.style.backgroundPosition ='center center';
	cover.style.backgroundRepeat ='no-repeat';
	cover.style.backgroundSize = $( window ).width()+'px auto';
	if(cover.style.backgroundImage == 'url("none")'){
		cover.style.backgroundImage = 'url("/sites/all/media/cover/welcome.jpg")'
		cover.style.height = '100px'
	$('#header-cover').height(100)
	.css('height','100px')
	.css('overflow','hidden')
	$('div.brand-name').css('top', '5px')
	$('h1#page-title').css('margin-top', '5px').css('color', '#0033CC')
	}else{
	cover.style.height = h+'px'
	$('#header-cover').height(h)
	.css('height',h+'px')
	.css('overflow','hidden')
	
	}
    //code ends
  }
};



})(jQuery);


/*
$(function () {
    var body = $('body');
    var backgrounds = [
      'url(http://static.jsbin.com/images/jsbin_static.png)', 
      'url(http://static.jsbin.com/images/popout.png)'];
    var current = 0;

    function nextBackground() {
        body.css(
            'background',
        backgrounds[current = ++current % backgrounds.length]);

        setTimeout(nextBackground, 5000);
    }
    setTimeout(nextBackground, 5000);
    body.css('background', backgrounds[0]);
});
var images = ['red','blue','green','purple','yellow'];
var quotes = ['bg1os.png','bg2os.png','bg3os.png','bg4os.png','bg5os.png'];

setInterval(function(){

var random = Math.floor(Math.random()*5);
var disquote = quotes[random];
var bg = $.inArray(disquote, quotes);

$(".bodyBG").fadeOut("fast",
     function () {
        $('#qtext').html(disquote);
        $(this).css('background-color', images[bg] );
        // Animation complete.
        $(this).fadeIn("fast");
    });
}, 1000);

data-background="{}"
*/